﻿using MiniBlinkPinvoke;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;

namespace MiniBlink.Core
{
    /// <summary>
    /// MiniBlink的接口
    /// </summary>
    public static class BlinkNative
    {
        static BlinkNative() { }

        /// <summary>
        /// MiniBlink动态库路径
        /// </summary>
        private const string BlinkBrowserdll = "node.dll";

        #region 系统接口函数

        [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
        public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
        [DllImport("user32.dll", EntryPoint = "SendMessageW")]
        public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetForegroundWindow();
        [DllImport("user32.dll")]
        public static extern int GetWindowTextLength(IntPtr hWnd);
        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int nMaxCount);

        public static Dictionary<string, Assembly> ResourceAssemblys { get; } = new Dictionary<string, Assembly>();

        #endregion

        /// <summary>
        /// 释放内存
        /// </summary>
        public static void ClearMemory()
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
            }
        }

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeInitialize();

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnCreateView(IntPtr webView, wkeCreateViewCallback callback, IntPtr param);


        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeFinalize();

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeInitializeEx(IntPtr settings);

        public static void wkeInitializeExWrap(wkeSettings settings)
        {
            int nSizeOfSettings = Marshal.SizeOf(settings);
            IntPtr intPtr = Marshal.AllocHGlobal(nSizeOfSettings);
            Marshal.StructureToPtr(settings, intPtr, true);
            BlinkNative.wkeInitializeEx(intPtr);
            Marshal.DestroyStructure(intPtr, typeof(wkeSettings));
        }

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeConfigure(IntPtr settings); // wkeSettings

        public static void wkeConfigureWrap(wkeSettings settings)
        {
            int nSizeOfSettings = Marshal.SizeOf(settings);
            IntPtr intPtr = Marshal.AllocHGlobal(nSizeOfSettings);
            Marshal.StructureToPtr(settings, intPtr, true);
            BlinkNative.wkeConfigure(intPtr);
            Marshal.DestroyStructure(intPtr, typeof(wkeSettings));
        }

        #region MiniBlink设置

        /// <summary>
        /// 设置无窗口模式下的绘制偏移。在某些情况下（主要是离屏模式），绘制的地方不在真窗口的(0, 0)处，就需要手动调用此接口
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetHandleOffset(IntPtr webView, int x, int y);

        /// <summary>
        /// 设置wkeWebView对应的窗口句柄。
        /// 注意：只有在无窗口模式下才能使用。如果是用wkeCreateWebWindow创建的webview，已经自带窗口句柄了。
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="wnd"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetHandle(IntPtr webView, IntPtr wnd);

        /// <summary>
        /// 开启关闭npapi插件，如flash
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="Enable"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetNpapiPluginsEnabled(IntPtr webView, bool Enable);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeLimitPlugins(IntPtr handle, [MarshalAs(UnmanagedType.I1)] bool b);

        /// <summary>
        /// 是否开启无头模式。开启后，将不会渲染页面，提升了网页性能。此功能方便用来实现一些爬虫，或者刷单工具
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="Enable"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetHeadlessEnabled(IntPtr webView, bool Enable);

        /// <summary>
        /// 绑定View请求时，所用IP，比如一台电脑两个IP的情况下，可以指定某个IP访问
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="netInterface"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetViewNetInterface(IntPtr webView, IntPtr netInterface);

        /// <summary>
        /// 关闭后，跨域检查将被禁止，此时可以做任何跨域操作，如跨域ajax，跨域设置iframe
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="Enable"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetCspCheckEnable(IntPtr webView, bool Enable);

        /// <summary>
        /// 是否新开窗口
        /// 关闭后，点a标签将不会弹出新窗口，而是在本窗口跳转
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="Enable"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetNavigationToNewWindowEnable(IntPtr webView, bool Enable);


        /// <summary>
        /// 判断frameId是否是主frame
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="frameId"></param>
        /// <returns></returns>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeIsMainFrame(IntPtr webView, IntPtr frameId);


        /// <summary>
        /// 开启触屏模式。开启后，鼠标消息将自动转换成触屏消息
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="Enable"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetTouchEnabled(IntPtr webView, bool Enable);

        /// <summary>
        /// 开启关闭鼠标消息，可以在开启触屏后，关闭鼠标消息
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="Enable"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetMouseEnabled(IntPtr webView, bool Enable);

        /// <summary>
        /// 是否启用内存缓存
        /// 开启内存缓存。网页的图片等都会在内存缓存里。关闭后，内存使用会降低一些，但容易引起一些问题，如果不懂怎么用，最好别开
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="Enable"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetMemoryCacheEnable(IntPtr webView, bool Enable);

        /// <summary>
        /// 开启一些实验性选项。
        /// <para>参数</para>
        /// <para>debugString：</para>
        /// <para>"showDevTools"	开启开发者工具，此时param要填写开发者工具的资源路径，如file:///c:/miniblink-release/front_end/inspector.html。注意param此时必须是utf8编码</para>
        /// <para>"wakeMinInterval"	设置帧率，默认值是10，值越大帧率越低</para>
        /// <para>"drawMinInterval"	设置帧率，默认值是3，值越大帧率越低</para>
        /// <para>"antiAlias"	设置抗锯齿渲染。param必须设置为"1"</para>
        /// <para>"minimumFontSize"	最小字体</para>
        /// <para>"minimumLogicalFontSize"	最小逻辑字体</para>
        /// <para>"defaultFontSize"	默认字体</para>
        /// <para>"defaultFixedFontSize"	默认fixed字体</para>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="fn"></param>
        /// <param name="param"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetDebugConfig(IntPtr handler, [MarshalAs(UnmanagedType.LPStr)] [In] string debugString, [MarshalAs(UnmanagedType.LPStr)] [In] string param);

        /// <summary>
        /// 打开开发者调试窗口
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="path"></param>
        /// <param name="callback"></param>
        /// <param name="param"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeShowDevtools(IntPtr webView, [In] [MarshalAs(UnmanagedType.LPWStr)] string path, wkeOnShowDevtoolsCallback callback, IntPtr param);

        /// <summary>
        /// 获取webview的UA
        /// </summary>
        /// <param name="handle"></param>
        /// <returns></returns>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeGetUserAgent(IntPtr handle);

        /// <summary>
        /// 设置webview的UA
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="str"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetUserAgent(IntPtr handle, [In] [MarshalAs(UnmanagedType.LPStr)] string str);

        /// <summary>
        /// 设置webview的UA
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="str"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetUserAgentW(IntPtr handle, [In] [MarshalAs(UnmanagedType.LPWStr)] string str);

        #endregion

        #region Cookie相关接口

        /// <summary>
        /// 获取页面的cookie
        /// </summary>
        /// <param name="webView"></param>
        /// <returns></returns>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeGetCookie(IntPtr webView);

        /// <summary>
        /// 获取页面的cookie
        /// </summary>
        /// <param name="webView"></param>
        /// <returns></returns>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern string wkeGetCookieW(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetCookieJarPath(IntPtr webView, [MarshalAs(UnmanagedType.LPWStr)] [In] string path);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetCookieJarFullPath(IntPtr webView, [MarshalAs(UnmanagedType.LPWStr)] [In] string path);

        /// <summary>
        /// 设置页面cookie。
        /// 注意：cookie必须符合curl的cookie写法。一个例子是：PERSONALIZE=123;expires=Monday, 13-Jun-2022 03:04:55 GMT; domain=.fidelity.com; path=/; secure
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="url"></param>
        /// <param name="cookie"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetCookie(IntPtr webView, [MarshalAs(UnmanagedType.LPArray)]byte[] url, [MarshalAs(UnmanagedType.LPArray)]byte[] cookie);

        [return: MarshalAs(UnmanagedType.I1)]
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeIsCookieEnabled(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetCookieEnabled(IntPtr webView, [MarshalAs(UnmanagedType.I1)] bool enable);


        #endregion

        #region 页面绘制相关接口

        /// <summary>
        /// 获取webveiw对应的窗口句柄。实现和wkeGetWindowHandle完全相同
        /// </summary>
        /// <param name="webView"></param>
        /// <returns></returns>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeGetHostHWND(IntPtr webView);

        /// <summary>
        /// 获取窗口对应的真实句柄。和wkeGetHostHWND的实现完全相同
        /// </summary>
        /// <param name="webView"></param>
        /// <returns></returns>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeGetWindowHandle(IntPtr webView);

        /// <summary>
        /// 获取页面的像素的简化版函数。
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="bits">外部申请并传递给mb的buffer，大小是webview宽度 * 高度 * 4 字节。</param>
        /// <param name="pitch">填0即可。这个参数玩过directX的人应该懂</param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkePaint(IntPtr webView, IntPtr bits, int pitch);

        /// <summary>
        /// 注意：此函数一般给3d游戏使用。另外频繁使用此接口并拷贝像素有性能问题。最好用wkeGetViewDC再去拷贝dc。
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="bits">外部申请并传递给mb的buffer，大小是bufWid * bufHei * 4 字节</param>
        /// <param name="bufWid">bits的宽</param>
        /// <param name="bufHei">bits的高</param>
        /// <param name="xDst">绘制到bits的哪个坐标</param>
        /// <param name="yDst">绘制到bits的哪个坐标</param>
        /// <param name="w">mb需要取的画面的起始坐标</param>
        /// <param name="h">mb需要取的画面的起始坐标</param>
        /// <param name="xSrc">mb需要取的画面的起始坐标</param>
        /// <param name="ySrc">mb需要取的画面的起始坐标</param>
        /// <param name="bCopyAlpha">是否拷贝画面的透明度值</param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkePaint2(IntPtr webView, IntPtr bits, int bufWid, int bufHei, int xDst, int yDst, int w, int h, int xSrc, int ySrc, [MarshalAs(UnmanagedType.I1)]bool bCopyAlpha);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkePaintDC(IntPtr handle, IntPtr hdc);

        /// <summary>
        /// 获取webview的DC
        /// </summary>
        /// <param name="webView"></param>
        /// <returns></returns>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeGetViewDC(IntPtr webView);


        [return: MarshalAs(UnmanagedType.I1)]
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeIsTransparent(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetTransparent(IntPtr webView, [MarshalAs(UnmanagedType.I1)] bool transparent);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeWindowOnPaint(IntPtr webView, IntPtr bits, int pitch);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnPaintUpdated(IntPtr webView, wkePaintUpdatedCallback callback, IntPtr callbackParam);

        #endregion

        #region 页面加载

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeLoadFile(IntPtr webView, [In, MarshalAs(UnmanagedType.LPWStr)] string filename);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeLoadHTML(IntPtr webView, IntPtr html);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeLoadHTMLW(IntPtr webView, [In, MarshalAs(UnmanagedType.LPWStr)] string html);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeLoadURL(IntPtr webView, IntPtr url);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
        public static extern void wkeLoadURLW(IntPtr webView, [In, MarshalAs(UnmanagedType.LPWStr)] string url);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
        public static extern void wkeLoadFileW(IntPtr webView, [In, MarshalAs(UnmanagedType.LPWStr)] string url);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
        public static extern void wkeLoadW(IntPtr webView, [In, MarshalAs(UnmanagedType.LPWStr)] string url);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnDocumentReady(IntPtr webView, wkeDocumentReadyCallback callback, IntPtr param);

        /// <summary>
        /// 可判断是不是主 frame 加载完成
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="callback"></param>
        /// <param name="param"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnDocumentReady2(IntPtr webView, wkeDocumentReadyCallback callback, IntPtr param);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnLoadingFinish(IntPtr webView, wkeLoadingFinishCallback callback, IntPtr param);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeReload(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetZoomFactor(IntPtr webView, float factor);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeStopLoading(IntPtr webView);

        #endregion

        #region 网页请求相关


        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeNetHookRequest(IntPtr job);

        /// <summary>
        /// 任何网络请求发起前会触发此回调
        /// <para>注意：</para>
        /// <para>1，此回调功能强大，在回调里，如果对job设置了wkeNetHookRequest，则表示mb会缓存获取到的网络数据，并在这次网络请求 结束后调用wkeOnLoadUrlEnd设置的回调，同时传递缓存的数据。在此期间，mb不会处理网络数据。</para>
        /// <para>2，如果在wkeLoadUrlBeginCallback里没设置wkeNetHookRequest，则不会触发wkeOnLoadUrlEnd回调。</para>
        /// <para>3，如果wkeLoadUrlBeginCallback回调里返回true，表示mb不处理此网络请求（既不会发送网络请求）。返回false，表示mb依然会发送网络请求。</para>
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="callback"></param>
        /// <param name="callbackParam"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnLoadUrlBegin(IntPtr webView, wkeLoadUrlBeginCallback callback, IntPtr callbackParam);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnLoadUrlEnd(IntPtr webView, wkeLoadUrlEndCallback callback, IntPtr callbackParam);

        /// <summary>
        /// 在wkeOnLoadUrlBegin回调里调用，表示设置http请求的MIME type
        /// </summary>
        /// <param name="job"></param>
        /// <param name="type"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
        public static extern void wkeNetSetMIMEType(IntPtr job, IntPtr type);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeNetSetURL(IntPtr job, [MarshalAs(UnmanagedType.LPStr)]string url);

        /// <summary>
        /// 在wkeOnLoadUrlEnd里被调用，表示设置hook后缓存的数据
        /// </summary>
        /// <param name="job"></param>
        /// <param name="buf"></param>
        /// <param name="len"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeNetSetData(IntPtr job, IntPtr buf, int len);

        /// <summary>
        /// 一个网络请求发送后，收到服务器response触发回调
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="callback"></param>
        /// <param name="param"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeNetOnResponse(IntPtr webView, wkeNetResponseCallback callback, IntPtr param);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="job"></param>
        /// <param name="mime">可以传nullptr</param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeNetGetMIMEType(IntPtr job, IntPtr mime);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkePostURL(IntPtr webView, [In, MarshalAs(UnmanagedType.LPStr)] string url, IntPtr data, int dataBytes);

        #endregion

        #region 菜单


        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetMenuItemText([In, MarshalAs(UnmanagedType.LPStr)] string item, [In, MarshalAs(UnmanagedType.LPStr)] string text);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetMenuItemVisible([In, MarshalAs(UnmanagedType.LPStr)] string item, [MarshalAs(UnmanagedType.I1)] bool enable);

        #endregion

        #region 网页操作相关

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSelectAll(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeCopy(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeCut(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkePaste(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeDelete(IntPtr webView);

        /// <summary>
        /// 网页调用alert会走到这个接口填入的回调
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="callback"></param>
        /// <param name="callbackParam"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnAlertBox(IntPtr webView, AlertBoxCallback callback, IntPtr callbackParam);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnConfirmBox(IntPtr webView, ConfirmBoxCallback callback);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnPromptBox(IntPtr webView, PromptBoxCallback callback);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetFocus(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeGetCaretRect(IntPtr webView, ref wkeRect rect);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeKillFocus(IntPtr webView);

        /// <summary>
        /// 重新设置页面的宽高。如果webView是带窗口模式的，会设置真窗口的宽高。
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="w"></param>
        /// <param name="h"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeResize(IntPtr webView, int w, int h);

        /// <summary>
        /// 页面是否可以后退
        /// </summary>
        /// <param name="webView"></param>
        /// <returns></returns>
        [return: MarshalAs(UnmanagedType.I1)]
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeCanGoBack(IntPtr webView);

        /// <summary>
        /// 强制让页面后退
        /// </summary>
        /// <param name="webView"></param>
        /// <returns></returns>
        [return: MarshalAs(UnmanagedType.I1)]
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeGoBack(IntPtr webView);

        /// <summary>
        /// 页面是否可以前进
        /// </summary>
        /// <param name="webView"></param>
        /// <returns></returns>
        [return: MarshalAs(UnmanagedType.I1)]
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeCanGoForward(IntPtr webView);

        /// <summary>
        /// 强制让页面前进
        /// </summary>
        /// <param name="webView"></param>
        /// <returns></returns>
        [return: MarshalAs(UnmanagedType.I1)]
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeGoForward(IntPtr webView);

        /// <summary>
        /// 给webview发送全选命令
        /// </summary>
        /// <param name="webView"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeEditorSelectAll(IntPtr webView);

        /// <summary>
        /// 取消选中
        /// </summary>
        /// <param name="webView"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeEditorUnSelect(IntPtr webView);

        /// <summary>
        /// 拷贝页面里被选中的字符串
        /// </summary>
        /// <param name="webView"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeEditorCopy(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeEditorCut(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeEditorUndo(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeEditorRedo(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeEditorDelete(IntPtr webView);


        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnNavigation(IntPtr webView, wkeNavigationCallback callback, IntPtr param);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnTitleChanged(IntPtr webView, TitleChangedCallback callback, IntPtr callbackParam);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnURLChanged(IntPtr webView, UrlChangedCallback callback, IntPtr callbackParam);

        /// <summary>
        /// 可以实现类似谷歌浏览器鼠标移动到带有超链接的地方，给出链接地址。
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="callback"></param>
        /// <param name="callbackParam"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnMouseOverUrlChanged(IntPtr webView, TitleChangedCallback callback, IntPtr callbackParam);

        /// <summary>
        /// URL 改变，可判断是否是主 frame 的url 改变
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="callback"></param>
        /// <param name="callbackParam"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnURLChanged2(IntPtr webView, UrlChangedCallback2 callback, IntPtr callbackParam);

        #endregion

        #region 键鼠操作

        [return: MarshalAs(UnmanagedType.I1)]
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeFireMouseEvent(IntPtr webView, uint message, int x, int y, uint flags);

        [return: MarshalAs(UnmanagedType.I1)]
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeFireMouseWheelEvent(IntPtr webView, int x, int y, int delta, uint flags);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool wkeFireKeyUpEvent(IntPtr webView, uint virtualKeyCode, uint flags, [MarshalAs(UnmanagedType.I1)] bool systemKey);

        [return: MarshalAs(UnmanagedType.I1)]
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeFireKeyDownEvent(IntPtr webView, uint virtualKeyCode, uint flags, [MarshalAs(UnmanagedType.I1)] bool systemKey);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool wkeFireKeyPressEvent(IntPtr webView, uint charCode, uint flags, [MarshalAs(UnmanagedType.I1)] bool systemKey);

        #endregion

        #region 下载相关

        /// <summary>
        /// 下载回调
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="callback"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnDownloadFile(IntPtr webView, wkeDownloadFileCallback callback, IntPtr param);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnDownload(IntPtr webView, wkeDownloadFileCallback callback, IntPtr param);

        #endregion

        #region 网页媒体相关


        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern float wkeMediaVolume(IntPtr webView);

        /// <summary>
        /// 设置音量，未实现
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="volume"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetMediaVolume(IntPtr webView, Single volume);

        /// <summary>
        /// 获取音量，未实现
        /// </summary>
        /// <param name="webView"></param>
        /// <returns></returns>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Single wkeGetMediaVolume(IntPtr webView);

        #endregion

        #region 字符处理方法

        /// <summary>
        /// 获取wkeString结构体对应的字符串，utf16编码
        /// </summary>
        /// <param name="string"></param>
        /// <returns></returns>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public static extern IntPtr wkeGetStringW(IntPtr @string);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public static extern IntPtr wkeToStringW(IntPtr @string);

        /// <summary>
        /// 获取wkeString结构体对应的字符串，utf8编码
        /// </summary>
        /// <param name="string"></param>
        /// <returns></returns>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeGetString(IntPtr @string);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeCreateStringW(IntPtr str, Int64 len);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeDeleteString(IntPtr str);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetWTFString(IntPtr wtfstr, [In] [MarshalAs(UnmanagedType.LPWStr)] string str);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeGetWTFString(IntPtr wtfstr);

        public static string Utf8IntptrToString(IntPtr ptr)
        {
            var data = new List<byte>();
            var off = 0;
            while (true)
            {
                var ch = Marshal.ReadByte(ptr, off++);
                if (ch == 0)
                {
                    break;
                }
                data.Add(ch);
            }
            return Encoding.UTF8.GetString(data.ToArray());
        }

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr Utf8StringToWkeChar([In, MarshalAs(UnmanagedType.LPStr)] string param0);

        #endregion

        #region jS 相关

        /// <summary>
        /// 绑定一个全局函数到主frame的window上。
        /// <para>注意：此接口只能绑定主frame，并且特别需要注意的是，因为历史原因，此接口是fastcall调用约定！（但wkeJsBindFunction不是）
        /// 另外此接口和wkeJsBindFunction必须在webview创建前调用</para>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="fn"></param>
        /// <param name="argCount"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.FastCall)]
        public static extern void jsBindFunction([MarshalAs(UnmanagedType.LPStr)] [In] string name, wkeJsNativeFunction fn, uint argCount);

        /// <summary>
        /// 和jsBindFunction功能类似，但更方便一点，可以传一个param做自定义数据。
        /// <para>此接口必须在webview创建前调用</para>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="fn"></param>
        /// <param name="param"></param>
        /// <param name="argCount"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeJsBindFunction([MarshalAs(UnmanagedType.LPStr)] [In] string name, wkeJsNativeFunction fn, IntPtr param, uint argCount);

        /// <summary>
        /// 对js winows绑定一个属性访问器，在js里windows.XXX这种形式调用时，fn会被调用
        /// </summary>
        /// <param name="name"></param>
        /// <param name="fn"></param>
        /// <param name="param"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeJsBindGetter([MarshalAs(UnmanagedType.LPStr)] [In] string name, wkeJsNativeFunction fn, IntPtr param);

        /// <summary>
        /// 对js winows绑定一个属性设置器。
        /// </summary>
        /// <param name="name"></param>
        /// <param name="fn"></param>
        /// <param name="param"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeJsBindSetter([MarshalAs(UnmanagedType.LPStr)] [In] string name, wkeJsNativeFunction fn, IntPtr param);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeJSCollectGarbge();

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeJSContextCreateCallback(ContextCreateCallback cb);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 wkeJSGet(IntPtr es, Int64 jsValue, [In, MarshalAs(UnmanagedType.LPWStr)] string proName);

        /// <summary>
        /// 直接执行JS代码
        /// </summary>
        /// <param name="es"></param>
        /// <param name="js"></param>
        /// <returns></returns>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 wkeJSEval(IntPtr es, [MarshalAs(UnmanagedType.LPWStr)] [In] string js);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 jsStringW(IntPtr es, IntPtr str);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 jsString(IntPtr es, IntPtr str);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern double jsToDouble(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr jsToString(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr jsToStringW(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern wkeJSData wkeJSGetData(IntPtr es, Int64 jsValue);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 jsArg(IntPtr es, int argIdx);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern int jsArgCount(IntPtr wkeJSState);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeGlobalExec(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern wkeJSType jsTypeOf(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeJSIsNumber(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeJSIsString(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeJSIsBool(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeJSIsObject(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeJSIsFunction(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeJSIsUndefined(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeJSIsNull(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeJSIsArray(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeJSIsTrue(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeJSIsFalse(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 wkeJSGetAt(IntPtr es, Int64 @object, int @index);

        /// <summary>
        /// WebView关联操作
        /// </summary>
        /// <param name="es"></param>
        /// <returns></returns>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeJSGetWebView(IntPtr es);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern float jsToFloat(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern int jsToInt(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        [return: MarshalAs(UnmanagedType.I1)]
        public static extern bool jsToBoolean(IntPtr es, Int64 v);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 wkeRunJS(IntPtr webView, IntPtr script);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 wkeRunJSW(IntPtr webView, [In] [MarshalAs(UnmanagedType.LPWStr)] string script);

        /// <summary>
        /// 可以在wkeOnDocumentReady2回调里注入JS执行 
        /// </summary>
        /// <param name="webView"></param>
        /// <param name="frameId"></param>
        /// <param name="script"></param>
        /// <param name="isInClosure"></param>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeRunJsByFrame(IntPtr webView, IntPtr frameId, IntPtr script, [MarshalAs(UnmanagedType.I1)] bool isInClosure);

        #region 创建JS基础变量

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 jsInt(IntPtr es, int n);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 jsFloat(IntPtr es, float f);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 jsDouble(IntPtr es, double d);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 jsBoolean(IntPtr es, [MarshalAs(UnmanagedType.I1)] bool b);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 jsUndefined(IntPtr es);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 jsNull(IntPtr es);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 jsTrue(IntPtr es);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 jsFalse(IntPtr es);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 wkeJSEmptyObject(IntPtr es);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern Int64 wkeJSEmptyArray(IntPtr es);

        #endregion

        #endregion

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnDidDownloadCallback(OnDidDownloadCallback _callback);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnReadFile(ReadFileCallback _callback);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeBeforeSendCallback(BeforeSendCallback _callback);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeExecCommand(IntPtr handle, [In] [MarshalAs(UnmanagedType.LPWStr)] string command, [In] [MarshalAs(UnmanagedType.LPWStr)] string args);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetDragFiles(IntPtr webView, Point clintPos, Point screenPos, IntPtr[] files, int filesCount);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern WkeCursorInfo wkeGetCursorInfoType(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeCallOnMainThread(EweCallBack _callback, IntPtr context);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeCallOnMainThreadAndWait(EweCallBack _callback, IntPtr context);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr WkeCharToUtf8String([In, MarshalAs(UnmanagedType.LPWStr)] string param0);

        [return: MarshalAs(UnmanagedType.I1)]
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool wkeContextMenuEvent(IntPtr webView, int x, int y, uint flags);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeCreateWebView();

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeCreateWindow(IntPtr hParent);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeDestroyWebView(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeEnableContextMenu(IntPtr webView, [MarshalAs(UnmanagedType.I1)] bool enable);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeEnableWindow(IntPtr webView, [MarshalAs(UnmanagedType.I1)] bool enable);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeFree(IntPtr ptr);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern int wkeGetContentHeight(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern int wkeGetContentWidth(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern int wkeGetHeight(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern int wkeGetWidth(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern float wkeGetZoomFactor(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeMalloc(int size);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnConsole(IntPtr webView, wkeConsoleMessageCallback callback, IntPtr param);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeOnDidDownloadCallback(DidDownloadCallback callback_);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeTitleW(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern void wkeSetStoragePath([MarshalAs(UnmanagedType.LPWStr)] [In] string directory);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeGetVersionString();

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeNetGetPostBody(IntPtr job);

        /// <summary>
        /// wkeRequestType 
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern wkeRequestType wkeNetGetRequestMethod(IntPtr job);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkeWebFrameGetMainFrame(IntPtr webView);

        [DllImport(BlinkBrowserdll, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr wkePrintToBitmap(IntPtr webView, IntPtr wkeWebFrameHandle, wkeScreenshotSettings settings);

    }
}
